package com.bana.fvs.controller;

import com.bana.fvs.code.DeviceStatus;
import com.bana.sys.code.DatabaseResult;
import com.bana.fvs.dao.LinkDeviceDAO;
import com.bana.fvs.model.*;
import com.bana.sys.utils.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 联动设备
 */
@RestController
@RequestMapping(value = "/linkdevice", method = RequestMethod.POST)
public class LinkDeviceController {

    @Resource
    private LinkDeviceDAO linkDeviceDAO;

    /**
     * 查询联动设备集合
     * @param request wqbm,sblx,sblx,分页 雾区编码
     * @return
     */
    @RequestMapping(value = "/getLinkDevices.do", method = RequestMethod.POST)
    public List<LinkDevice> getLinkDevices(@RequestBody TokenRequest<LinkDevice> request) {
        return linkDeviceDAO.getLinkDevices(request.getData().getWqbm(),request.getData().getSblx());
    }

    /**
     * 新增联动设备详情
     * @param request 联动设备
     * @return
     */
    @RequestMapping(value = "/insertLinkDevice.do",method =RequestMethod.POST )
    public ActionResult insertLinkDevice(@RequestBody TokenRequest<LinkDevice> request){
        ActionResult actionResult=new ActionResult();
        LinkDevice linkDevice=request.getData();
        linkDevice.setSbzt(DeviceStatus.Error);
        linkDeviceDAO.insertLinkDevice(linkDevice);
        actionResult.setCzjg(DatabaseResult.Success);
        actionResult.setKey(request.getData().getSbbm());
        return actionResult;
    }

    /**
     * 更新联动设备详情
     * @param request 联动设备
     * @return
     */
    @RequestMapping(value = "/updateLinkDevice.do",method =RequestMethod.POST )
    public ActionResult updateLinkDevice(@RequestBody TokenRequest<LinkDevice> request){
        ActionResult actionResult=new ActionResult();
        linkDeviceDAO.updateLinkDevice(request.getData());
        actionResult.setCzjg(DatabaseResult.Success);
        return actionResult;
    }

    /**
     * 删除联动设备详情
     * @param request sbbm 设备编码
     * @return
     */
    @RequestMapping(value = "/deleteLinkDevice.do",method =RequestMethod.POST )
    public ActionResult deleteLinkDevice(@RequestBody TokenRequest<LinkDevice> request){
        ActionResult actionResult=new ActionResult();
        linkDeviceDAO.deleteLinkDevice(request.getData().getSbbm());
        actionResult.setCzjg(DatabaseResult.Success);
        return actionResult;
    }
}
